﻿using Moqikaka.Model;
using Moqikaka.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Moqikaka.BLL
{
    /// <summary>
    /// 回归活动缓存
    /// </summary>
    public class PlayerReturnCache
    {
        /// <summary>
        /// 缓存Dictionary
        /// </summary>
        private static SafeDictionary<string, JoinOldPlayerReturnCache> playerReturnCache =
            new SafeDictionary<string, JoinOldPlayerReturnCache>();


        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="partnerId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static JoinOldPlayerReturnCache Get(string userId, int partnerId)
        {
            var cacheKey = string.Format("{0}_{1}", userId, partnerId);
            return playerReturnCache.Get(cacheKey);
        }

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="key">key</param>
        /// <returns></returns>
        public static JoinOldPlayerReturnCache Get(string key)
        {
            return playerReturnCache.Get(key);
        }

        /// <summary>
        /// 写入
        /// </summary>
        /// <param name="partnerId">partnerId</param>
        /// <param name="userId">userId</param>
        /// <param name="cahe">value</param>
        public static void Set(string userId, int partnerId,JoinOldPlayerReturnCache cahe)
        {
            var cacheKey = string.Format("{0}_{1}", userId, partnerId);

            playerReturnCache.Set(cacheKey, cahe);
        }

        /// <summary>
        /// 写入
        /// </summary>
        /// <param name="key">key</param>
        /// <param name="cahe">value</param>
        public static void Set(string key, JoinOldPlayerReturnCache cahe)
        {
            cahe.LastCheckTime = DateTime.Now;
            playerReturnCache.Set(key,cahe);
        }
    }
}
